package cn.jlonely.xyhx.app.mapper;

import cn.jlonely.xyhx.pojo.Review;
import cn.jlonely.xyhx.pojo.vo.VitoVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AppVitoMapper {
    /**
     * 获取某个活动排名
     * @param id
     * @return
     */
    @Select("select judge_id,topic, cover_image,introduce, create_time,user_id,number,ranking_id,judge_status from review_table where ranking_id = #{id}  and judge_status = 1 ORDER BY number DESC;")
    @Results({
            @Result(property = "id", column = "judge_id")
    })
    List<Review> getVitoInfo(Integer id);

    /**
     * 判断用户是否已经投票
     * @param rankingId
     * @param userId
     * @return
     */
    @Select("SELECT COUNT(*) FROM vote_record WHERE ranking_id = #{rankingId} AND user_id = #{userId}")
    boolean selectVito(@Param("rankingId") Integer rankingId, @Param("userId") Integer userId);

    /**
     * 参与投票
     * @param vitoVo
     */
    @Insert("insert into vote_record(user_id,judge_id,ranking_id) values(#{userId},#{judgeId},#{rankingId})")
    void createVito(VitoVo vitoVo);
}
